package com.episode.duetapi.controller;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.episode.duetapi.model.Banner;
import com.episode.duetapi.service.BannerService;
import com.episode.duetapi.utils.ResultCode;
import com.episode.duetapi.utils.ResultTools;

import ch.qos.logback.core.net.SyslogOutputStream;

@RestController
@RequestMapping("banner")
public class BannerController {
	
	@Autowired
	private BannerService bannerService;
	
	@RequestMapping(value="add",method=RequestMethod.POST)
	public Object addBanner(Banner banner) {
		banner.setIsDisabled(0);
		banner.setCreatetime(new Date());
		Integer i = bannerService.insertBanner(banner);
		if(i>0) {
			return ResultTools.getDataResult(ResultCode.DATA_SUCCESS);
		}
		return ResultTools.getDataResult(ResultCode.DATA_ERROR);
	}
	
	@RequestMapping(value="getBannerList",method=RequestMethod.POST)
	public Object getBannerList(Map paramMap) {
		List<Banner> bannerList = bannerService.getBannerList(paramMap);
		return ResultTools.getDataResult(bannerList);
	} 

	@RequestMapping(value="getBanner",method=RequestMethod.POST)
	public Object getBanner(Integer id) {          
		Banner banner = bannerService.getBannerById(id);
		return ResultTools.getDataResult(banner);
	}
	
	@RequestMapping(value="updateBanner",method=RequestMethod.POST)
	public Object updateBanner(Banner banner) {
		Integer i = bannerService.updateBanner(banner);
		if(i>0) {
			return ResultTools.getDataResult(ResultCode.DATA_SUCCESS);
		}
		return ResultTools.getDataResult(ResultCode.DATA_ERROR);
	}
	
	@RequestMapping(value="deleteBanner",method=RequestMethod.POST)
	public Object deleteBanner(Integer id) {
		Integer i = bannerService.deleteBanner(id);
		if(i>0) {
			return ResultTools.getDataResult(ResultCode.DATA_SUCCESS);
		}
		return ResultTools.getDataResult(ResultCode.DATA_ERROR);
	}
	
	@RequestMapping(value="upperAndLowersFrames",method=RequestMethod.POST)
	public Object upperAndLowersFrames(Integer[] ids,Integer isDisabled) {
		Map paramMap = new HashMap();
		paramMap.put("ids", ids);
		paramMap.put("isDisabled", isDisabled);
		Integer i = bannerService.updateBannerStatus(paramMap);
		if(i>0) {
			return ResultTools.getDataResult(ResultCode.DATA_SUCCESS);
		}
		return ResultTools.getDataResult(ResultCode.DATA_ERROR);
	}
	
	
	
}
